// MouseStatus.h
//
#ifndef MOUSESTATUS_H
#define MOUSESTATUS_H

class QGraphicsView;
class QMouseEvent;
class QGraphicsSceneMouseEvent;

namespace IDS {
namespace IDEAS	{
namespace OpenGLView {
namespace Fwk {

class MouseStatus
{
public:
	enum Button {
		BUTTON_NONE   = 0x0000, // No button or key pressed.
		BUTTON_LEFT   = 0x0001, // Left mouse button pressed.
		BUTTON_MIDDLE = 0x0002, // Middle mouse button pressed.
		BUTTON_RIGHT  = 0x0004, // Right mouse button pressed.
		WHEEL         = 0x0008, // Mouse wheel activated.
		KEY_SHIFT     = 0x0010, // Shift key pressed.
		KEY_CTRL      = 0x0020, // Ctrl key pressed.
		KEY_ALT       = 0x0040, // Alt key pressed.
		MODIFIER_MASK = 0x00F0, // Mask to get modifiers only
		BUTTON_MASK   = 0x000F, // Mask to get buttons only
	};


private:
	QGraphicsView *view;

	Button eventToButton( QGraphicsSceneMouseEvent *e );
	Button eventToButton( QMouseEvent *e );

	int xPos,yPos;
	int xPrev,yPrev;
	int pressedButton;
	int releasedButton;
	bool moving;

public:
	MouseStatus();
	~MouseStatus(){}
	
	void reset();
	void setView(QGraphicsView *gv);
	void set(QGraphicsSceneMouseEvent *e, bool updateButtons, bool invertY = true);
	void set(QMouseEvent *e, bool updateButtons, bool invertY = true);

	// -----------------------------------------------------------------------------------------------
	bool isMoving()		const {return moving;}
	int  x()			const {return xPos;}
	int  y()			const {return yPos;}
	int  buttonDown()	const {return pressedButton;}
	int  buttonUp()		const {return releasedButton;}
	int  prevX()		const {return xPrev;}
	int  prevY()		const {return yPrev;}
	// -----------------------------------------------------------------------------------------------

};

}}}}
#endif
